package com.ruoyi.web.controller.help;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.help.domain.HelpStudent;
import com.ruoyi.help.dto.EvaluateDto;
import com.ruoyi.help.service.IHelpStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 帮扶预约Controller
 * 
 * @author ruoyi
 * @date 2022-10-08
 */
@RestController
@RequestMapping("/help/helpstudent")
public class HelpStudentController extends BaseController
{
    @Autowired
    private IHelpStudentService helpStudentService;

    /**
     * 查询帮扶预约列表
     */
    @PreAuthorize("@ss.hasPermi('help:helpstudent:list')")
    @GetMapping("/list")
    public TableDataInfo list(HelpStudent helpStudent)
    {
        startPage();
        List<HelpStudent> list = helpStudentService.selectHelpStudentList(helpStudent);
        return getDataTable(list);
    }

    /**
     * 导出帮扶预约列表
     */
    @PreAuthorize("@ss.hasPermi('help:helpstudent:export')")
    @Log(title = "帮扶预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HelpStudent helpStudent)
    {
        List<HelpStudent> list = helpStudentService.selectHelpStudentList(helpStudent);
        ExcelUtil<HelpStudent> util = new ExcelUtil<HelpStudent>(HelpStudent.class);
        util.exportExcel(response, list, "帮扶预约数据");
    }

    /**
     * 获取帮扶预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('help:helpstudent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(helpStudentService.selectHelpStudentById(id));
    }

    /**
     * 新增帮扶预约
     */
    @PreAuthorize("@ss.hasPermi('help:helpstudent:add')")
    @Log(title = "帮扶预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HelpStudent helpStudent)
    {
        return toAjax(helpStudentService.insertHelpStudent(helpStudent));
    }

    /**
     * 修改帮扶预约
     */
    @PreAuthorize("@ss.hasPermi('help:helpstudent:edit')")
    @Log(title = "帮扶预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluateDto evaluateDto)
    {
        return toAjax(helpStudentService.updateHelpStudent(evaluateDto));
    }

    /**
     * 删除帮扶预约
     */
    @PreAuthorize("@ss.hasPermi('help:helpstudent:remove')")
    @Log(title = "帮扶预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(helpStudentService.deleteHelpStudentByIds(ids));
    }
}
